let ajax = getApp().globalData.ajax;
let app = getApp().globalData;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    rzjnUrl:'http://image.tanwancat.com/657ff6d092941aee7cdfed5d07aa2d2b_48_48.jpeg',//认证技能
    ddzxUrl:'https://wx4.sinaimg.cn/thumb150/a6fbb400gy1frs93rgd6aj201c01c0rg.jpg',//订单中心
    wdqbUrl:'https://wx1.sinaimg.cn/thumb150/a6fbb400gy1frs93t6srmj201c01c3y9.jpg',//我的钱包
    zxkfUrl:'https://wx3.sinaimg.cn/thumb150/a6fbb400gy1frs93zbvirj201c01cwe9.jpg',//在线客服
    wdzzUrl:'http://image.tanwancat.com/629327efb1c0b6b44a61ac52b2dacbfd_48_48.jpeg',//我的资质
    jdjlUrl:'http://image.tanwancat.com/5517659a01215cbc15877ffcf5d0fe31_48_48.jpeg',//接单记录
    jdszUrl:'http://image.tanwancat.com/6e6d448ab03ec0358382e206e8d7a5d7_48_48.jpeg',//接单设置
    defulImg: 'https://bpic.588ku.com/element_pic/01/36/33/28573c10f97f97f.jpg!/fw/254/quality/90/unsharp/true/compress/true',
    userInfo:{},
    hasUserInfo:false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let userInfo = wx.getStorageSync('userInfo');
    if (userInfo){
      this.setData({ userInfo, hasUserInfo:true});
    }else{
      this.setData({ hasUserInfo: false });
    }
    let self=this;
    wx.getSetting({
      success: function (res) {
        if (res.authSetting['scope.userInfo']) {
          wx.getUserInfo({
            success (res) {
              

            }
          })
        }
      }
    })
  },
  toOrderList(){
    wx.navigateTo({
      url:'../orderList/orderList'
    })
  },
  toApplySkill() {
    wx.navigateTo({
      url: '../applySkill/applySkill'
    })
  },

  toMyWallet() {
    wx.navigateTo({
      url: '../myWallet/myWallet'
    })
  },

  toSetOrder(){
    wx.navigateTo({
      url: '../setOrder/setOrder'
    })
  },

  toOrderRecord(){
    wx.navigateTo({
      url: '../orderRecord/orderRecord'
    })
  },

  bindGetUserInfo: function (e) {

    this.setData({ userInfo: e.detail.userInfo, hasUserInfo:true });

    app.userInfo=this.data.userInfo;
debugger
    //登录信息
    Object.assign(app.loginUser, this.data.userInfo);
    //聊天头像昵称更新
    app.subscriber.emit('UPDATE_MY_INFO', app.loginUser)

    app.loginUser.avatar = app.loginUser.avatarUrl;
    app.loginUser.nick = app.loginUser.nickName;
  
    
    //本地存储
    wx.setStorage({
      key: "userInfo",
      data: e.detail.userInfo,
    })

    let json = {
      userinfo: JSON.stringify(this.data.userInfo),
      token: wx.getStorageSync('Cookie'),
    }
    
    ajax('user/profile', json, 'POST').then(res => {
      
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})